package com.javaweb.controller;

import com.javaweb.controller.common.ResponseResult;

import com.javaweb.service.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/11/6 8:44
 */


@RestController
@RequestMapping("/validate")
@Slf4j
public class ValidateController {

    @PostMapping("/exception")
    @Validated
    public ResponseResult<String> globalException(@NotBlank(message = "用户名不能为空") @RequestParam  String username,
                                                  @NotBlank(message = "密码不能为空") @RequestParam  String password) {
        log.info("username:{}, password: {}", username, password);
        return ResponseResult.ok("success");
    }
    @PostMapping("/param/json")
    public ResponseResult<String> validateObject(@Validated @RequestBody UserDto userDto) {
        log.info("username:{}, password: {}", userDto.getUsername(), userDto.getPassword());
        return ResponseResult.ok("success");
    }




}
